import JSEncrypt from '@/utils/jsencrypt'
import { ZZ_PUBLIC_KEY,RSA_PUBLIC_KEY, ZZ_PRIVATE_KEY } from '@/constants'

//加密方法
const encryption = (params) => {
  console.log(params, '加密之前')
  const encrypt = new JSEncrypt()
  encrypt.setPublicKey(ZZ_PUBLIC_KEY)
  const encryptPassword = encrypt.encrypt(JSON.stringify(params))
  console.log(encryptPassword, '加密之后')
  return encryptPassword
}
//加密方法
const encryptionRSA = (params) => {
  console.log(params, '加密之前')
  const encrypt = new JSEncrypt()
  encrypt.setPublicKey(RSA_PUBLIC_KEY)
  const encryptPassword = encrypt.encrypt(params)
  console.log(encryptPassword, '加密之后')
  return encryptPassword
}
// 解密方法
const decrypt = (params) => {
  const decrypt = new JSEncrypt()
  decrypt.setPrivateKey(ZZ_PRIVATE_KEY)
  const encryptPassword = decrypt.decrypt(JSON.parse(JSON.stringify(params)))
  console.log(encryptPassword, '解密之后')
  return encryptPassword
}

export {
  encryption,decrypt,encryptionRSA
}